package ml.kupin.item.controller;

import ml.kupin.item.vo.WebItem;
import ml.kupin.pojo.TbItem;
import ml.kupin.pojo.TbItemDesc;
import ml.kupin.service.ItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * Created by 小柯(Allen Kerr) on 17.5.4 17:57.
 */
@Controller
@RequestMapping("/item")
public class ItemController {

    @Autowired
    private ItemService itemService;

    @RequestMapping(value = "/{itemId}", method = RequestMethod.GET)
    public String showItemDetail(@PathVariable Long itemId, Model model) {
        //获取商品信息
        TbItem tbItem = itemService.getItemById(itemId);
        //转换为WebItem
        WebItem webItem = new WebItem(tbItem);
        //获取商品描述信息
        TbItemDesc itemDesc = itemService.getItemDescById(itemId);
        //添加到model中取
        model.addAttribute("item", webItem);
        model.addAttribute("itemDesc", itemDesc);
        //返回逻辑视图
        return "item";
    }


}
